using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNASpelProjekt
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        #region Member Variables

        GraphicsDeviceManager graphics;
        private SpriteBatch spriteBatch;

        public static SpriteFont font;

        public static Texture2D titleImage;
        public static Texture2D level1;

        public static Texture2D arrowImage;

        public static Texture2D deathImage1;
        public static Texture2D deathImage2;

        public static Texture2D playerImage;
        public static Texture2D playerRunningImage1;
        public static Texture2D playerRunningImage2;
        public static Texture2D playerRunningImage3;
        public static Texture2D playerDamagedImage;
        public static Texture2D playerJumpingImage;

        public static Texture2D ultrosImage;

        public static Texture2D playerStandardShotImage;
        public static Texture2D ultrosShotImage;

        public static SoundEffect playerStandardShotSound;
        public static SoundEffect ultrosShotSound;
        public static SoundEffect damageSound;
        public static Song level1Music;        

        public static bool quit;
        public static Map map;

        #endregion

        #region constructors
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 640;
            graphics.PreferredBackBufferHeight = 480;
            TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0);
            Content.RootDirectory = "Content";
        }

        #endregion

        #region protected methods

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {            
            quit = false;
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            level1 = Content.Load<Texture2D>("Background");
            titleImage = Content.Load<Texture2D>("title");

            arrowImage = Content.Load<Texture2D>("arrow");

            deathImage1 = Content.Load<Texture2D>("death1");
            deathImage2 = Content.Load<Texture2D>("death2");

            playerImage = Content.Load<Texture2D>("Actors/Player");
            playerRunningImage1 = Content.Load<Texture2D>("Actors/PlayerRunning1");
            playerRunningImage2 = Content.Load<Texture2D>("Actors/PlayerRunning2");
            playerRunningImage3 = Content.Load<Texture2D>("Actors/PlayerRunning3");
            playerDamagedImage = Content.Load<Texture2D>("Actors/PlayerDamaged");
            playerJumpingImage = Content.Load<Texture2D>("Actors/PlayerJumping");

            ultrosImage = Content.Load<Texture2D>("Actors/Ultros");

            playerStandardShotImage = Content.Load<Texture2D>("Actors/Bullet");
            ultrosShotImage = Content.Load<Texture2D>("Actors/UltrosShot");

            playerStandardShotSound = Content.Load<SoundEffect>("Sound/PlayerStandardShotSound");
            ultrosShotSound = Content.Load<SoundEffect>("Sound/ultrosShotSound");
            damageSound = Content.Load<SoundEffect>("Sound/DamageSound");

            level1Music = Content.Load<Song>("Sound/Christopher_Baklid_-_Max_Game_loop_v1");
            
            font = Content.Load<SpriteFont>("Times New Roman");

            map = new TitleScreen();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here          
            map.Update(gameTime);
            if (quit)
            {
                this.Exit();
            }
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {                       
            // TODO: Add your drawing code here
            GraphicsDevice.Clear(Color.CornflowerBlue);
            map.Draw(gameTime, spriteBatch); 
            base.Draw(gameTime);
        }

        #endregion

    }
}
